<template>
<span class="scan">
<input type="text" @keyup="gets($event)" v-model="inputnull">
</span>
</template>

<script>
import _ from "lodash";
export default {
  name: "scan",
  props:["gogo"],
  data() {
    return {
      inputnull:''
    };
  },
 watch:{
   gogo:function(val,oldval){
          if(val>0){
              this.inputnull=""
          }
      
   }
 },
  methods: {
    gets: _.debounce(function(ev) {
      //console.log(ev.target.value);
      // let params = new URLSearchParams();
      // params.append("barcode", ev.target.value);
      // params.append("id", JSON.parse(localStorage.user).userid);
      // params.append("level", JSON.parse(localStorage.user).level);
      this.$http
        .post(
          "http://medical.qingguo188.com/user-drug-warehouse/search",
           {
            barcode: ev.target.value,
            id:JSON.parse(localStorage.user).userid,
            level: JSON.parse(localStorage.user).level
          },
          {
            headers: {
              "Content-Type": "application/x-www-form-urlencoded"
            }
          }
        )
        .then(
          rester => {
              // console.log(rester.data)
            if(rester.data.status==1){
              console.log(rester.data.$message.info)
             this.$emit('searchList',rester.data.$message.info);

            }else if(rester.data.status==3){
              console.log("666")
              this.$emit('searchList',this.inputnull);
            }
            // console.log(rester.data.$message.info);
            //this.$emit("searchList", rester.data.$message.info);
          },
          function() {
            //this.$layer.alert("网络错误！");
          }
        );
    }, 1000)
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.gray {
  background: #008df6;
  color: white;
}
.scan {
  display: inline-block;
  position: relative;
  vertical-align: middle;
  width: 180px;
}
.positionul {
  position: absolute;
  background: white;
  width: 100%;
}
.positionul li {
  text-align: center;
  height: 30px;
  width: 180px;
  line-height: 30px;
}
.positionul li:hover {
  background: #afc8db;
  color: white;
}
.scan p {
  margin-top: 5px;
  color: red;
}
</style>
